home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club (Business) 1997 July / Software of the Month Club - Business (Volume 239) (July 1997).iso / pc / code / g.dxr / 00010_G LongStock handlers.ls < prev    next >
Encoding:
Text File  |  1996-02-15  |  16.4 KB  |  439 lines

  1. global gHotRects, gObjects, sQTCharSprite, gHaveNavs, gCPU, gTimerList, gSoundchannels
  2.  
  3. on setupG11D
  4.   if getaProp(getaProp(gStates, #BeenThere), #G11D) = 0 then
  5.     set newAccountBalance to getaProp(getaProp(gObjects, #LongTermStock), #ProsperoAccountBalance)
  6.     MakeDynamic(#LongTermStock, #AccountBalance, newAccountBalance)
  7.   end if
  8.   if (getaProp(getaProp(gObjects, #LongKeyBoard), #keyTargetState) = #stockEntry) and (getaProp(getaProp(gObjects, #LongTermStock), #InfoKFJump) = #false) then
  9.     resetGTextFields()
  10.     put string(getaProp(getaProp(gObjects, #LongTermStock), #validPIN)) into field "G11LPINDisplay.txt"
  11.     put "$" && string(getaProp(getaProp(gObjects, #LongTermStock), #AccountBalance)) into field "G11LBalanceDisplay.txt"
  12.     reLoadCompanyFields()
  13.     set companyButtonDown to getaProp(getaProp(gObjects, #LongStocks), #currentChildDown)
  14.     if companyButtonDown <> #none then
  15.       AddObjects([#LFractalAnalysisHRect, #LFractalStatisticHRect])
  16.       showCompanyDisplays()
  17.     end if
  18.   end if
  19.   set companyButtonDown to getaProp(getaProp(gObjects, #LongStocks), #currentChildDown)
  20.   if companyButtonDown <> #none then
  21.     set companyObjDown to getaProp(gObjects, companyButtonDown)
  22.     MakeDynamic(companyButtonDown, #DisplayState, #down)
  23.     if voidp(getaProp(gHotRects, #LFractalAnalysisHRec)) then
  24.       AddObjects([#LFractalAnalysisHRect, #LFractalStatisticHRect])
  25.     end if
  26.   end if
  27. end
  28.  
  29. on setupG11F
  30.   DoLInfoPersistenceHRect()
  31. end
  32.  
  33. on reLoadCompanyFields
  34.   set companyList to getaProp(getaProp(gObjects, #LongStocks), #Children)
  35.   repeat with companyRef in companyList
  36.     set companyObj to getaProp(gObjects, companyRef)
  37.     set months to getaProp(companyObj, #monthsEntered)
  38.     set dataRef to getAt(getaProp(companyObj, #Children), 1)
  39.     set dataField to getaProp(getaProp(getaProp(gObjects, dataRef), #cast), #INIT)
  40.     if integerp(months) then
  41.       put string(months) into field dataField
  42.     end if
  43.   end repeat
  44. end
  45.  
  46. on clearStockEntries
  47.   set companyList to getaProp(getaProp(gObjects, #LongStocks), #Children)
  48.   repeat with companyRef in companyList
  49.     set companyObj to getaProp(gObjects, companyRef)
  50.     MakeDynamic(companyRef, #monthsEntered, #none)
  51.     set dataRef to getAt(getaProp(companyObj, #Children), 1)
  52.     set dataField to getaProp(getaProp(getaProp(gObjects, dataRef), #cast), #INIT)
  53.     put " " into field dataField
  54.   end repeat
  55. end
  56.  
  57. on cleanupG11D
  58.   DelObjects([#LFractalAnalysisHRect, #LFractalStatisticHRect])
  59.   if getaProp(getaProp(gObjects, #LongTermStock), #InfoKFJump) = #false then
  60.     DelObjects([#LongBalanceDisplay, #LongPINDisplay, #LStocMHdata, #LStocORdata, #LStocMIdata, #LStocATdata, #LStocHAdata])
  61.     clearGTextFields()
  62.     setLongKeyBoardState(#on)
  63.     set companyButtonDown to getaProp(getaProp(gObjects, #LongTermStock), #companySelected)
  64.     if companyButtonDown <> #none then
  65.       MakeDynamic(companyButtonDown, #DisplayState, #UP)
  66.     end if
  67.     MakeDynamic(#LongRunGroup, #lastButtonClicked, #none)
  68.     MakeDynamic(#LongTermStock, #companySelected, #none)
  69.     MakeDynamic(#LongTermStock, #pinEntries, 0)
  70.     MakeDynamic(#LongStocks, #currentChildDown, #none)
  71.     MakeDynamic(#LongTermStock, #enteredPIN, #none)
  72.     MakeDynamic(#LongTermStock, #keyTargetState, #PINEntry)
  73.     MakeDynamic(#LongTermStock, #stocksRun, [])
  74.     MakeDynamic(#LongKeyBoard, #keyTargetState, #PINEntry)
  75.     MakeDynamic(#LongKeyBoard, #dataEntryState, #newEntry)
  76.     setaProp(getaProp(getaProp(gObjects, #LongFeedback), #cast), #INIT, the number of cast "G11EPIN.PCT")
  77.     setaProp(getaProp(getaProp(gObjects, #LongFractalGraph), #cast), #INIT, the number of cast "G11DGraphDummy")
  78.     setaProp(getaProp(getaProp(gObjects, #LongFractalInfo), #cast), #INIT, the number of cast "cNullSprite")
  79.   end if
  80.   setaProp(getaProp(gObjects, #LongTermStock), #InfoKFJump, #false)
  81. end
  82.  
  83. on DoLongInfo
  84.   setaProp(getaProp(gObjects, #LongTermStock), #InfoKFJump, #true)
  85.   Jumptokey(#G11F)
  86. end
  87.  
  88. on DoLongStockKeyPad KeyNum
  89.   if getaProp(getaProp(gObjects, #LongKeyBoard), #keyTargetState) = #PINEntry then
  90.     set currentPIN to getLongPINDisplayValue()
  91.     if integerp(KeyNum) then
  92.       if getLongKeyBoardState() = #on then
  93.         if field "G11LPINDisplay.txt" = " " then
  94.           put string(KeyNum) into field "G11LPINDisplay.txt"
  95.         else
  96.           put string(KeyNum) after field "G11LPINDisplay.txt"
  97.         end if
  98.         if the number of chars in field "G11LPINDisplay.txt" = 4 then
  99.           setLongKeyBoardState(#enterPIN)
  100.         end if
  101.       end if
  102.     else
  103.       if KeyNum = #return then
  104.         if currentPIN = getaProp(getaProp(gObjects, #LongTermStock), #validPIN) then
  105.           doValidLongPIN()
  106.         else
  107.           doInValidLongPIN()
  108.         end if
  109.       end if
  110.     end if
  111.   else
  112.     if (getaProp(getaProp(gObjects, #LongKeyBoard), #keyTargetState) = #stockEntry) and (KeyNum <> #return) then
  113.       set companyRef to getaProp(getaProp(gObjects, #LongStocks), #currentChildDown)
  114.       if companyRef <> #none then
  115.         set hotfield to getHotFieldCastNum(companyRef)
  116.         if not integerp(value(field hotfield)) or (getaProp(getaProp(gObjects, #LongKeyBoard), #dataEntryState) = #newEntry) then
  117.           put " " into field hotfield
  118.           MakeDynamic(#LongKeyBoard, #dataEntryState, #inProgress)
  119.         end if
  120.         if field hotfield = " " then
  121.           put string(KeyNum) into field hotfield
  122.         else
  123.           put string(KeyNum) after item 1 of field hotfield
  124.         end if
  125.         MakeDynamic(companyRef, #monthsEntered, integer(field hotfield))
  126.         if the number of chars in field hotfield = 3 then
  127.           setLongKeyBoardState(#off)
  128.         end if
  129.       end if
  130.     end if
  131.   end if
  132. end
  133.  
  134. on getHotFieldCastNum inCompanyRef
  135.   set hotFieldName to "G11" & string(inCompanyRef) & "data.txt"
  136.   return the number of cast hotFieldName
  137. end
  138.  
  139. on getLongPINDisplayValue
  140.   set pinCastNum to the number of cast "G11LPINDisplay.txt"
  141.   set pinDisplayValue to value(field "G11LPINDisplay.txt")
  142.   return pinDisplayValue
  143. end
  144.  
  145. on doValidLongPIN
  146.   MakeDynamic(#LongTermStock, #enteredPIN, #valid)
  147.   playSound("G11ent.aif", #keyframeCast)
  148.   MakeDynamic(#LongKeyBoard, #keyTargetState, #stockEntry)
  149.   MakeDynamic(#LongKeyBoard, #State, #on)
  150.   set currentAccountBalance to getaProp(getaProp(gObjects, #LongTermStock), #AccountBalance)
  151.   put "$" && string(currentAccountBalance) into field "G11LBalanceDisplay.txt"
  152.   displayLongFeedback("cNullSprite")
  153.   setaProp(getaProp(getaProp(gObjects, #LongFeedback), #cast), #INIT, the number of cast "cNullSprite")
  154.   updateStage()
  155. end
  156.  
  157. on doInValidLongPIN
  158.   MakeDynamic(#LongTermStock, #enteredPIN, #none)
  159.   set currentPINEntries to getaProp(getaProp(gObjects, #LongTermStock), #pinEntries)
  160.   set currentPINEntries to currentPINEntries + 1
  161.   MakeDynamic(#LongTermStock, #pinEntries, currentPINEntries)
  162.   if (getLongPINDisplayValue() = getaProp(getaProp(gObjects, #LongTermStock), #shortPIN)) and (currentPINEntries < 3) then
  163.     put " " into field "G11LPINDisplay.txt"
  164.     displayLongFeedback("G11E_NO.PCT")
  165.     Startthetimer(3 * 60, "jumptoKey (#G11A)")
  166.   else
  167.     put " " into field "G11LPINDisplay.txt"
  168.     MakeDynamic(#LongTermStock, #enteredPIN, #invalid)
  169.     playSound("G11abort.aif", #keyframeCast)
  170.     displayLongFeedback("G11EINV.PCT")
  171.     updateStage()
  172.     CountGTime(3)
  173.     displayLongFeedback("G11EPIN.PCT")
  174.     setLongKeyBoardState(#on)
  175.   end if
  176.   if currentPINEntries = 3 then
  177.     doGEndGame()
  178.   end if
  179. end
  180.  
  181. on displayLongFeedback inCastName
  182.   set feedbackCastNum to the number of cast inCastName
  183.   set longFeedBackSprite to getaProp(getaProp(gObjects, #LongFeedback), #SpriteNum)
  184.   set the castNum of sprite longFeedBackSprite to feedbackCastNum
  185.   updateStage()
  186. end
  187.  
  188. on setLongKeyBoardState inState
  189.   if symbolp(inState) then
  190.     MakeDynamic(#LongKeyBoard, #State, inState)
  191.   else
  192.     put "bad parameter passed to setShortKeyBoardState"
  193.   end if
  194. end
  195.  
  196. on getLongKeyBoardState
  197.   set kBoardOList to getaProp(gObjects, #LongKeyBoard)
  198.   set keyBoardState to getaProp(kBoardOList, #State)
  199.   return keyBoardState
  200. end
  201.  
  202. on DoLCompanySelectKeyPad companySelected
  203.   if voidp(getaProp(gHotRects, #LFractalAnalysisHRec)) then
  204.     AddObjects([#LFractalAnalysisHRect, #LFractalStatisticHRect])
  205.   end if
  206.   showCompanyDisplays()
  207.   if getLongKeyBoardState() <> #enterPIN then
  208.     MakeDynamic(#LongKeyBoard, #State, #on)
  209.     MakeDynamic(#LongKeyBoard, #dataEntryState, #newEntry)
  210.   end if
  211.   MakeDynamic(#LongTermStock, #companySelected, getaProp(getaProp(gObjects, #LongStocks), #currentChildDown))
  212. end
  213.  
  214. on showCompanyDisplays
  215.   set companyRef to getaProp(getaProp(gObjects, #LongStocks), #currentChildDown)
  216.   if getaProp(getaProp(gObjects, #LFractalAnalysisHRect), #State) = #selected then
  217.     set infoRef to #LFractalAnalysisHRect
  218.   else
  219.     if getaProp(getaProp(gObjects, #LFractalStatisticHRect), #State) = #selected then
  220.       set infoRef to #LFractalStatisticHRect
  221.     else
  222.       set infoRef to #LFractalAnalysisHRect
  223.     end if
  224.   end if
  225.   set infoSpriteNum to getaProp(getaProp(gObjects, #LongFractalInfo), #SpriteNum)
  226.   set graphSpriteNum to getaProp(getaProp(gObjects, #LongFractalGraph), #SpriteNum)
  227.   set infoDisplayCastNum to getaProp(getaProp(getaProp(getaProp(getaProp(gObjects, #LongFractalInfo), #cast), #displayAssigns), companyRef), infoRef)
  228.   set graphDisplayCastNum to getaProp(getaProp(getaProp(getaProp(getaProp(gObjects, #LongFractalGraph), #cast), #displayAssigns), companyRef), infoRef)
  229.   set the castNum of sprite infoSpriteNum to infoDisplayCastNum
  230.   set the castNum of sprite graphSpriteNum to graphDisplayCastNum
  231.   setaProp(getaProp(getaProp(gObjects, #LongFractalGraph), #cast), #INIT, graphDisplayCastNum)
  232.   setaProp(getaProp(getaProp(gObjects, #LongFractalInfo), #cast), #INIT, infoDisplayCastNum)
  233.   updateStage()
  234. end
  235.  
  236. on DoLFractalAnalysisHRect
  237.   MakeDynamic(#LFractalAnalysisHRect, #State, #selected)
  238.   MakeDynamic(#LFractalStatisticHRect, #State, #notSelected)
  239.   showCompanyDisplays()
  240. end
  241.  
  242. on DoLFractalStatisticHRect
  243.   MakeDynamic(#LFractalStatisticHRect, #State, #selected)
  244.   MakeDynamic(#LFractalAnalysisHRect, #State, #notSelected)
  245.   showCompanyDisplays()
  246. end
  247.  
  248. on DoLongRun
  249.   if getaProp(getaProp(gObjects, #LongTermStock), #enteredPIN) <> #valid then
  250.     flashFeedback()
  251.   else
  252.     set runSoundChannel to playSound("G11run.aif", #keyframeCast)
  253.     if gCPU = #mpc then
  254.       set myTimer to the ticks
  255.       repeat while the ticks < (myTimer + 15)
  256.         CursorandUpdate()
  257.       end repeat
  258.     end if
  259.     repeat while soundBusy(runSoundChannel)
  260.       if the mouseDown then
  261.         if inside(point(the mouseH, the mouseV), rect(174, 31, 265, 62)) then
  262.           exit
  263.         end if
  264.       end if
  265.       CursorandUpdate()
  266.     end repeat
  267.     calcProfit()
  268.   end if
  269.   MakeDynamic(#LongRunGroup, #lastButtonClicked, #LongRun)
  270. end
  271.  
  272. on findSoundChannel soundName
  273.   if not voidp(gSoundchannels) then
  274.     repeat with i = 1 to count(gSoundchannels)
  275.       set channelNum to getPropAt(gSoundchannels, i)
  276.       set channelInfo to getaProp(gSoundchannels, channelNum)
  277.       if getaProp(channelInfo, #name) = soundName then
  278.         return channelNum
  279.       end if
  280.     end repeat
  281.   end if
  282.   return 0
  283. end
  284.  
  285. on DoLongAbort
  286.   if getaProp(getaProp(gObjects, #LongTermStock), #enteredPIN) <> #valid then
  287.     flashFeedback()
  288.   else
  289.     clearStockEntries()
  290.   end if
  291.   MakeDynamic(#LongRunGroup, #lastButtonClicked, #LongAbort)
  292. end
  293.  
  294. on DoLongStatus
  295.   if getaProp(getaProp(gObjects, #LongTermStock), #enteredPIN) <> #valid then
  296.     flashFeedback()
  297.   else
  298.     if getaProp(getaProp(gObjects, #LongRunGroup), #lastButtonClicked) = #LongRun then
  299.       set answerStatus to checkAnswers()
  300.       displayStatusMessages(answerStatus)
  301.       if answerStatus = #correct then
  302.         MakeDynamic(#LongTermStock, #solved, #true)
  303.         setaProp(getaProp(gStates, #Conditions), #LongStock, #true)
  304.       end if
  305.     end if
  306.   end if
  307.   setaProp(getaProp(gObjects, #LongRunGroup), #lastButtonClicked, #LongStatus)
  308. end
  309.  
  310. on flashFeedback
  311.   set longFeedBackSprite to getaProp(getaProp(gObjects, #LongFeedback), #SpriteNum)
  312.   repeat with i = 1 to 3
  313.     CountGTime(0.5)
  314.     set the type of sprite longFeedBackSprite to 0
  315.     updateStage()
  316.     CountGTime(0.5)
  317.     set the type of sprite longFeedBackSprite to 1
  318.     updateStage()
  319.   end repeat
  320. end
  321.  
  322. on calcProfit
  323.   set monthsMH to value(field "G11LStocMHdata.txt")
  324.   set monthsOR to value(field "G11LStocORdata.txt")
  325.   set monthsMI to value(field "G11LStocMIdata.txt")
  326.   set monthsAT to value(field "G11LStocATdata.txt")
  327.   set monthsHA to value(field "G11LStocHAdata.txt")
  328.   set newStocksRun to getaProp(getaProp(gObjects, #LongTermStock), #stocksRun)
  329.   set newAccountBalance to getaProp(getaProp(gObjects, #LongTermStock), #AccountBalance)
  330.   if getOne(newStocksRun, #LstocMH) = 0 then
  331.     set ProfitMH to monthsMH / 5 * -1 * 20 * (1 - 0.16389999999999999)
  332.     set newAccountBalance to newAccountBalance + ProfitMH
  333.     add(newStocksRun, #LstocMH)
  334.   end if
  335.   if (getOne(newStocksRun, #LstocOR) = 0) and (monthsOR = 78) then
  336.     set ProfitOR to 78 * 10 * 0.76379999999999992
  337.     set newAccountBalance to newAccountBalance + ProfitOR
  338.     add(newStocksRun, #LstocOR)
  339.   end if
  340.   if (getOne(newStocksRun, #LstocMI) = 0) and (monthsMI = 50) then
  341.     set ProfitMI to 50 * 5 * 0.72009999999999996
  342.     set newAccountBalance to newAccountBalance + ProfitMI
  343.     add(newStocksRun, #LstocMI)
  344.   end if
  345.   if (getOne(newStocksRun, #LstocAT) = 0) and (monthsAT > 0) and (monthsAT < 95) then
  346.     set ProfitAT to power(-1, random(10)) * 15 * 0.84749999999999992 * monthsAT
  347.     set newAccountBalance to newAccountBalance + ProfitAT
  348.     add(newStocksRun, #LstocAT)
  349.   end if
  350.   if (getOne(newStocksRun, #LstocHA) = 0) and (monthsHA = 25) then
  351.     set ProfitHA to 25 * 2 * 0.61739999999999995
  352.     set newAccountBalance to newAccountBalance + ProfitHA
  353.     add(newStocksRun, #LstocHA)
  354.   end if
  355.   if checkAnswers() = #correct then
  356.     set newAccountBalance to 20000000
  357.   end if
  358.   MakeDynamic(#LongTermStock, #stocksRun, newStocksRun)
  359.   put "$" && integer(newAccountBalance) into field "G11LBalanceDisplay.txt"
  360.   MakeDynamic(#LongTermStock, #AccountBalance, integer(newAccountBalance))
  361. end
  362.  
  363. on displayStatusMessages answerStatus
  364.   set statusMessageSpriteNum to getaProp(getaProp(gObjects, #LongStatusFeedback), #SpriteNum)
  365.   if answerStatus = #incorrect then
  366.     set firstMessageCastNum to the number of cast "G11E_N01.PCT"
  367.     set the castNum of sprite statusMessageSpriteNum to firstMessageCastNum + random(10)
  368.     updateStage()
  369.   else
  370.     if answerStatus = #correct then
  371.       playSound("G11statG.aif", #keyframeCast)
  372.       set firstMessageCastNum to the number of cast "G11E_Y01.PCT"
  373.       repeat with i = 0 to 3
  374.         set the castNum of sprite statusMessageSpriteNum to firstMessageCastNum + i
  375.         CountGTime(2)
  376.         updateStage()
  377.       end repeat
  378.     end if
  379.   end if
  380. end
  381.  
  382. on checkAnswers
  383.   if (value(field "G11LStocMHdata.txt") = 0) and (value(field "G11LStocORdata.txt") = 78) and (value(field "G11LStocMIdata.txt") = 50) and (value(field "G11LStocHAdata.txt") = 25) then
  384.     return #correct
  385.   else
  386.     return #incorrect
  387.   end if
  388. end
  389.  
  390. on DoLongInfoReturn
  391.   Jumptokey(#G11D)
  392. end
  393.  
  394. on DoLInfoPersistenceHRect
  395.   MakeDynamic(#LongTermStockInfo, #textSelected, #LInfoPersistenceHRect)
  396.   setLongInfoDisplays()
  397. end
  398.  
  399. on DoLInfoRandomHRect
  400.   MakeDynamic(#LongTermStockInfo, #textSelected, #LInfoRandomHRect)
  401.   setLongInfoDisplays()
  402. end
  403.  
  404. on DoLInfoAntiPersistenceHRect
  405.   MakeDynamic(#LongTermStockInfo, #textSelected, #LInfoAntiPersistenceHRect)
  406.   setLongInfoDisplays()
  407. end
  408.  
  409. on DoLInfoFractalAnalysisHRect
  410.   MakeDynamic(#LongTermStockInfo, #graphSelected, #LInfoFractalAnalysisHRect)
  411.   setLongInfoDisplays()
  412. end
  413.  
  414. on DoLInfoFractalStatisticHRect
  415.   MakeDynamic(#LongTermStockInfo, #graphSelected, #LInfoFractalStatisticHRect)
  416.   setLongInfoDisplays()
  417. end
  418.  
  419. on setLongInfoDisplays
  420.   set textInfoSpriteNum to getaProp(getaProp(gObjects, #LongTextDisplayInfo), #SpriteNum)
  421.   set graphInfoSpriteNum to getaProp(getaProp(gObjects, #LongGraphDisplayInfo), #SpriteNum)
  422.   set textInfo to getaProp(getaProp(gObjects, #LongTermStockInfo), #textSelected)
  423.   set graphInfo to getaProp(getaProp(gObjects, #LongTermStockInfo), #graphSelected)
  424.   set textInfoDisplayCastNum to getaProp(getaProp(getaProp(getaProp(getaProp(gObjects, #LongTextDisplayInfo), #cast), #displayAssigns), textInfo), graphInfo)
  425.   set graphInfoDisplayCastNum to getaProp(getaProp(getaProp(getaProp(getaProp(gObjects, #LongGraphDisplayInfo), #cast), #displayAssigns), textInfo), graphInfo)
  426.   set the castNum of sprite textInfoSpriteNum to textInfoDisplayCastNum
  427.   set the castNum of sprite graphInfoSpriteNum to graphInfoDisplayCastNum
  428.   updateStage()
  429. end
  430.  
  431. on DoLongLogoff
  432.   Jumptokey(#G11a)
  433. end
  434.  
  435. on cleanupG11F
  436.   MakeDynamic(#LongTermStockInfo, #textSelected, #LInfoPersistenceHRect)
  437.   MakeDynamic(#LongTermStockInfo, #textSelected, #LInfoFractalAnalysisHRect)
  438. end
  439.